#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class CString
{
public:
	CString();
    CString(const char*);
    ~CString();
    CString(const CString& obj);
    CString& operator=(const CString& obj);
    int getLength()const;
    char* getStr()const;
    const CString operator+(const CString& obj)const;
    friend ostream& operator<<(ostream& os,const CString& obj)
    {
        os<<obj.getStr();
        return os;
    }
private:
    char* str;
};
CString::CString()
{
	str = new char[1];
    str[0] = '\0';
}

CString::CString(const char* s)
{
    
    if(NULL == s)
    {
        str = new char[1];
        str[0] = '\0';
    }
    else
    {
    	str = new char[strlen(s)+1];
    	strcpy(str,s);
    }
    
}
CString::~CString()
{
    delete []str;
}
CString::CString(const CString& obj)
{
   	str = new char[obj.getLength()];
    strcpy(str,obj.getStr());
}
CString& CString::operator=(const CString& obj)
{
   	if(this == &obj)
    {
      	return *this;
    }
    else
    {
      	delete []str;
        str = new char[obj.getLength()];
      	strcpy(str,obj.getStr());           
    }
    return *this;
}
int CString::getLength()const
{
    return (strlen(str)+1);
}
char* CString::getStr()const
{
     return str;
}
const CString CString::operator+(const CString& obj)const
{
	return CString(strcat(str,obj.getStr()));
}


int main()
{
    CString s1("dsdffds");
    CString s2("You!");
    s1 = s1+s2;
    CString s3(s1);
    cout<<endl<<s1;
    cout<<endl<<s3;
     system("pause");
    return 0;
}
